import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import axios from "@/utils/request";

export const Profile = defineStore('Profile', () => {
    let profile = ref({
        userId:undefined,
        staffPhoto:'',
        mobile:'',
        username:'',
        roles:[],
        companyId:'',
        company:'',
        city:'',
        base64Img:''
    })
    let imageUrl = ref('')
    let isLogin = ref(false)

    let getProfile = () => {
        axios.get("/sys/profile").then((res) => {
            console.log(res,'检测获取个人信息');
            if (res.success) {
                profile.value = res.data;
                imageUrl.value = profile.value.base64Img;
               console.log(res.data.roles.points)
               localStorage.setItem('roles',JSON.stringify(res.data.roles.points));
                isLogin.value = true;
            } else {   
                isLogin.value = false;
            }
        });
    }
    return { getProfile,profile,isLogin,imageUrl }
})